In [1]:
# ATMS 305 -- Fall, 2024 -- Lab01: Satellite
# >>>>>  Theo Xiong
#
# WELCOME TO YOUR FIRST ASSIGNMENT !
# Each "cell" in Jupyter Notebooks can contain
# comments, like those here -- starting with "#" --
# or Python code, or 'rich' text called "Markdown."
# You can run the entire notebook with "Run All", under Runtime.
# To run a single code "cell" - one at a time - click on the
#   cell and then hold Shift and hit the Return (or Enter) key.
# This cell is all comments, so "running it" does precisely nothing.
In [2]:
# >>> A. IMPORT
# Import the Python "modules" that we need.
# Many modules are standard, such that "import" is sufficient.
# Others may require first building / downloading the software.
# We will use the Python "matplotlib" Plotting module (as: "plt")
#         and the matplotlib Image module to read the image ("mpimg")
import matplotlib.pyplot as plt
import numpy as np
In [4]:
# >>> B. GET IMAGE FROM THE WEB using WGET
# Get a NOAA image as discussed in class.
# Use "wget" to get (retrieve) the image, by running wget as a "shell escape" command in Jupyter
#  >> Putting ! (exclamation) at the start of the line runs the command "shell".
#     A "shell" is a command interpreter, running on the compute node serving you.
# HERE: Get the image, name it "image.jpg"
# WGET options:
#   -q    Quiet; do things quietly.  Leave off the "progress bar" ...
#   -N    No retrieval unless newer: Don't get file unless newer than file we have.
#   -O    Name the output (our copy of the file) something other than the original name.
#         Note: "-N" is ignored if -O is used.
#   -v    Verbose option.  Try this if things aren't working!
#   -h    Help: !wget -h gets all the details for you.

# Gilma no longer available. I picked Hurricane Francien
!wget -O image.jpg https://cdn.star.nesdis.noaa.gov/FLOATER/AL062024/GEOCOLOR/20242552110_GOES16-ABI-FL-GEOCOLOR-AL062024-1000x1000.jpg
--2024-09-11 22:08:41--  https://cdn.star.nesdis.noaa.gov/FLOATER/AL062024/GEOCOLOR/20242552110_GOES16-ABI-FL-GEOCOLOR-AL062024-1000x1000.jpg
Resolving cdn.star.nesdis.noaa.gov (cdn.star.nesdis.noaa.gov)... 140.90.107.146, 140.90.107.147, 2610:20:8000:3002:beef:face:0:101, ...
Connecting to cdn.star.nesdis.noaa.gov (cdn.star.nesdis.noaa.gov)|140.90.107.146|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 672735 (657K) [image/jpeg]
Saving to: ‘image.jpg’

image.jpg           100%[===================>] 656.97K   552KB/s    in 1.2s    

2024-09-11 22:08:43 (552 KB/s) - ‘image.jpg’ saved [672735/672735]

In [5]:
# >>> C. READ IN IMAGE
# We read in a satellite image as it exists in our local Colab space.
# So it should be named 'image.jpg' not ABI-FD-GEOCOLOR-1808x1808.jpg, for example.
# The function "imread" is used here.  The URL appears in red.
# The Python "variable" that holds the data here should be called "satellite".
satellite = plt.imread('image.jpg')
In [7]:
# >>> D. Find DIMENSIONS of the image ARRAY ('satellite' not 'image.jpg')
# Use .shape to find the dimensions.
# This is a 2-D image ... but it has three dimensions!
# 1. First dimension  (Python index 0): pixels (picture elements) in Y direction (ROWS)
# 2. Second dimension (Python index 1): pixels in X direction (COLUMNS)
dim = satellite.shape
rows, cols = dim[0], dim[1]
In [8]:
# >>> D. FIND and PRINT the image DIMENSIONS
# Before we display the image, we first determine its dimensions.
# We use the "shape" attributes of our "satellite" variable,
#   and print the X, Y dimensions of the image picture elements (pixels).
# 1. Store the first [0] dimension in variable "rows"
# 2. Store the second [1] dimension in variable "cols" (columns)
# 3. Print the result with: Satellite image dimensions are #### x ####
#    ... where #### x #### is replaced with the COLUMNS and ROWS
#        Note: columns x rows, not rows x columns!!!!
print('Satellite image dimensions are {} x {}'.format(cols, rows))
Satellite image dimensions are 1000 x 1000
In [17]:
# >>> E. SHOW IMAGE
# 1. CREATE a Python figure, with dpi=300 to set the dots-per-inch we want.
#      ( if dpi=300 is too big, use a smaller number )
#      plt.figure() options include:  dpi=###, figsize=(X,Y)
#      Info: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html
# 2. DISPLAY the satellite image with "imshow" from matplotlib.image
#      Note: imshow() wants the VARIABLE containing the image,
#        NOT the name of the image, and NOT the url from which you got it.
# 3. Add a TITLE (appropriate to image you are showing)
# 4. Add X-AXIS label: Columns increasing to right
# 5. Add Y-AXIS label: Rows increasing down

plt.figure(dpi=300)
plt.imshow(satellite)
plt.title('Hurricane Francien');
plt.xlabel('Columns increasing to right');
plt.ylabel('Rows increasing down');
No description has been provided for this image
In [14]:
# >>> F. UPPER MISSISSIPPI VALLEY - GEOCOLOR
# Repeat the steps above, but ...
#   for North America
#          > Upper Mississippi Valley
#                > all channels (choose GeoColor)
# Make the title say Upper Mississippi Valley - Geocolor
!wget -O image1.jpg https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/umv/GEOCOLOR/20242552201_GOES16-ABI-umv-GEOCOLOR-600x600.jpg
satellite1 = plt.imread('image1.jpg')
plt.figure(dpi=300)
plt.imshow(satellite1)
plt.title('Upper Mississippi Valley - Geocolor');
plt.xlabel('Columns increasing to right');
plt.ylabel('Rows increasing down');
--2024-09-11 22:13:07--  https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/umv/GEOCOLOR/20242552201_GOES16-ABI-umv-GEOCOLOR-600x600.jpg
Resolving cdn.star.nesdis.noaa.gov (cdn.star.nesdis.noaa.gov)... 140.90.107.146, 140.90.107.147, 2610:20:8000:3002:beef:face:0:100, ...
Connecting to cdn.star.nesdis.noaa.gov (cdn.star.nesdis.noaa.gov)|140.90.107.146|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 215289 (210K) [image/jpeg]
Saving to: ‘image1.jpg’

image1.jpg          100%[===================>] 210.24K   249KB/s    in 0.8s    

2024-09-11 22:13:08 (249 KB/s) - ‘image1.jpg’ saved [215289/215289]

No description has been provided for this image
In [15]:
# >>> G. UPPER MISSISSIPPI VALLEY - WATER VAPOR
# Repeat the steps above, but ...
#   for North America
#          > Upper Mississippi Valley
#                > but choose band 10
# Make the title say: Upper Mississippi Valley Vapor
!wget -O image2.jpg https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/umv/10/20242552131_GOES16-ABI-umv-10-1200x1200.jpg
satellite2 = plt.imread('image2.jpg')
plt.figure(dpi=300)
plt.imshow(satellite2)
plt.title('Upper Mississippi Valley Vapor');
plt.xlabel('Columns increasing to right');
plt.ylabel('Rows increasing down');
--2024-09-11 22:14:09--  https://cdn.star.nesdis.noaa.gov/GOES16/ABI/SECTOR/umv/10/20242552131_GOES16-ABI-umv-10-1200x1200.jpg
Resolving cdn.star.nesdis.noaa.gov (cdn.star.nesdis.noaa.gov)... 140.90.107.147, 140.90.107.146, 2610:20:8000:3002:beef:face:0:101, ...
Connecting to cdn.star.nesdis.noaa.gov (cdn.star.nesdis.noaa.gov)|140.90.107.147|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 870247 (850K) [image/jpeg]
Saving to: ‘image2.jpg’

image2.jpg          100%[===================>] 849.85K   719KB/s    in 1.2s    

2024-09-11 22:14:11 (719 KB/s) - ‘image2.jpg’ saved [870247/870247]

No description has been provided for this image
In [18]:
# >>> I. Given: CURRENT DATE/TIME
# Show the current date/time - Universal Coordinated Time (UTC)
from time import gmtime, strftime, localtime
strftime("Current day/time: %Y-%m-%d %H:%M:%S UTC", gmtime()) # UTC/GMT time
Out[18]:
'Current day/time: 2024-09-11 22:15:22 UTC'
In [ ]:
# USE THIS cell to SAVE NOTEBOOK as HTML
# 1. LEAVE this cell COMMENTED OUT until your code works.
# 2. Still with bottom lines commented out, save notebook.ipynb file to your PC.
# 3. Upload the .ipynb file from your PC to Colab space
# 4. NOW uncomment this cell -- remove the '#' in the last two lines.
# 5. Change filename below (after "--to html") to this notebook's name
# 6. Run JUST this cell.
# 7. Find the new .html file; Refresh the Colab file list if need be
# 8. Save (from 3-dots) the .html file to your PC.
# 9. Upload both the .ipynb and the .html files to MOODLE.
#%%shell
#jupyter nbconvert --to html  Lab01_Satellite.ipynb
In [ ]:
# End of our first Jupyter Notebook.